// 1.定义数组
var numbers = [1, 2, 3, 4]

// 2.for实现累加
var total = 0
for (var i = 0; i < numbers.length; i++) {
    total += numbers[i]
}
console.log(total) // 10

// 3.使用forEach
var total = 0
numbers.forEach(item => {
    total += item
})
console.log(total)

// 4.使用reduce方法
var total = numbers.reduce((pre, cur) => {
    return pre + cur
})
console.log(total)
